package AuxFunctions;

import java.util.Arrays;

import GA.Chromosome;

public class PopulationFun {
	
	public static Chromosome[] sortPopulation(Chromosome[] population){ 
		Arrays.sort(population);
		return population;
	}
	
	public static void setScores(Chromosome[] population){
		// Calculate total aptitude
		int sumAptitude = 0;
		for (int i = 0; i < population.length; i++)
			sumAptitude += population[i].getAptitude();
		
		// Set score & score_acum to the entire population
		double score_acum = 0;
		for (int i = 0; i < population.length; i++){
			population[i].setScore(population[i].getAptitude() / sumAptitude);
			population[i].setScore_acum(population[i].getScore() + score_acum);
			score_acum += population[i].getScore();
		}
	}

	public static Chromosome[] evaluate(Chromosome[] population) {
		for (int i = 0; i < population.length; i++)
			population[i].setAptitude(population[i].evaluate());
		return population;
	}

}
